home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / help / IF < prev    next >
Text File  |  1994-04-25  |  829b  |  48 lines

  1. IF:
  2.  
  3.     The if statement is very similar to the C if statement. 
  4.  
  5.     if ( expression )
  6.     {
  7.       statement(s)
  8.     else
  9.       statement(s)
  10.     }
  11.  
  12.     The "else" is optional, and the braces are always required.
  13.     The differences between the C-language if-statement and RLaB's
  14.     are due to the special demands of an interactive language.
  15.  
  16.     Examples:
  17.  
  18.     if ( init ) 
  19.         {
  20.       mass = 10.0;
  21.       inertia = 3*mass/length^3;
  22.       init = 0;
  23.     }
  24.  
  25.     if(class(data) == "string") 
  26.     {
  27.       fprintf(file, data);
  28.     else
  29.       write(file, data);
  30.     }
  31.  
  32.     if( class(v) != "matrix" ) { error(); }
  33.  
  34.     At present there is no explicit elseif statement. However the
  35.     else if behavior can be implemented as it is in C (although
  36.     RLaB's syntax is somewhat clumsy). For example:
  37.  
  38.     if( test1 ) 
  39.     {
  40.       x = a;
  41.     else if( test2 ) {
  42.       x = b;
  43.     else if( test3 ) {
  44.       x = c;
  45.     else 
  46.       error();
  47.     }}}
  48.